package edu.hws.GA;

//package edu.hws.GA;

import java.awt.*;
import java.awt.event.*;

public class GAFrame extends Frame {

   public static void main(String[] args) {
      System.out.println("A simple genetic algorithms demo.\n" +
                  "David Eck, eck@hws.edu, http://math.hws.edu/eck/");
      if (args.length >= 1)
         new GAFrame(null);
      else
         new GAFrame(null);
   }
   
   private GACanvas world;
   private Launcher owner;
   
   public GAFrame(Launcher myOwner) {
      super("The World");
      owner = myOwner;
      world = new GACanvas(this);
      add(world, BorderLayout.CENTER);
      addWindowListener( new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
               close();
            }
            public void windowClosed(WindowEvent evt) {
              if (owner == null)  // running as an application
                 System.exit(0);
              else  
                owner.frameHasClosed();
            }
            public void windowOpened(WindowEvent evt) {
               world.start();
            }
         });
      setMenuBar(world.getMenuBar());
      pack();
      world.rWin = new ReportWin();
      show();
      setResizable(false);
      if (owner != null)
         owner.frameHasOpened();
   }
   
   
   void close() {
      world.stop();
      world.rWin.dispose();
      dispose();
      if (owner == null)  // running as an application
        System.exit(0);
      else
        owner.frameHasClosed();
   }
   

}
